package com.yaojiaxun.logisticsPlatformSystem.controller;

import com.yaojiaxun.logisticsPlatformSystem.entity.CertificateInfo;
import com.yaojiaxun.logisticsPlatformSystem.service.CertificateInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * @Auther: yjx_j
 * @Date: 2019/1/22 11:00
 * @Description:
 */
@Controller
public class CertificateController {

    @Autowired
    CertificateInfoService certificateInfoService;

    @RequestMapping("/certificate_manage")
    public String certificateManageIndex(@RequestParam(defaultValue = "1") Integer page, Map<String, Object> map){
        map.put("pageDTO", certificateInfoService.findPage(page));
        return "system/certificate/certificate_manage";
    }

    @RequestMapping("/certificate_detail_company")
    public String getDetailCom(@RequestParam("certificateId") Long certificateId, @RequestParam("page") Integer page, Map<String, Object> map){
        map.put("page", page);
        map.put("certificateInfo", certificateInfoService.findCertificateById(certificateId));
        return "system/certificate/certificate_detail_company";
    }

    @RequestMapping("/certificate_update_after_com")
    public String updateCertificateAfterCom(@RequestParam("page") Integer page, CertificateInfo certificateInfo){
        certificateInfoService.updateCertificate(certificateInfo);
        return "redirect:/certificate_manage?page="+page;
    }

    @RequestMapping("/certificateAddBeforeCom")
    public String addCertificateBeforeCom(){
        return "system/certificate/certificate_com_add";
    }

    @RequestMapping("/certificate_add_after_com")
    public String addCertificateAfterCom(CertificateInfo certificateInfo){
        certificateInfoService.addCertificateInfo(certificateInfo);
        return "redirect:/certificate_manage";
    }

    @RequestMapping("/certificateDelete")
    public String deleteCertificate(@RequestParam("certificateId") Long certificateId, @RequestParam("page") Integer page){
        certificateInfoService.deleteCertificateInfo(certificateId);
        return "redirect:/certificate_manage?page=" + page;
    }

    @RequestMapping("/certificate_detail_company_name")
    public String findCertificateByComName(@RequestParam("comName") String comName, Map<String, Object> map){
        map.put("page", 1);
        map.put("certificateInfo", certificateInfoService.findCertificateByComName(comName));
        return "system/certificate/certificate_detail_company_name";
    }
}
